package week_home_work02;

import java.util.Scanner;

/**
 * @author zdl
 * @date 2024/11/22
 */
public class Demo33 {
    public static void main(String[] args) {
        //实现一个数字猜谜游戏。
        int randNum = (int)(Math.random()*10)+1;
        System.out.println(randNum);
        Scanner sc = new Scanner(System.in);
        int guess = 0;
        int count = 0;
        while (guess != randNum && count < 5){
            System.out.println("请猜一个整数(1-10):");
            guess = sc.nextInt();
            count++;
            if (guess < randNum){
                System.out.println("猜小了！！");
            } else if (guess>randNum) {
                System.out.println("猜大了");
            }else {
                System.out.println("恭喜你用了"+count+"次机会猜对了！！！！");
                return;
            }
            if (count == 5){
                System.out.println("很遗憾你5次机会用完了都没有猜对！");
            }
        }
    }
}
